package com.example.javaairportflightanalysis.dao;


import com.example.javaairportflightanalysis.domin.userpojo.Role;
import com.example.javaairportflightanalysis.domin.userpojo.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * (Role)表数据库访问层
 *
 */
@Mapper
public interface RoleMapper {
    @Select("SELECT TR.keyword\n" +
            "FROM t_role TR\n" +
            "INNER JOIN t_user_role TUR ON TR.id = TUR.role_id\n" +
            "WHERE TUR.user_id = #{id};")
        List<String> getRoles(@Param("id") Integer userId);

    @Select("SELECT TR.*\n" +
            "FROM t_role TR\n" +
            "INNER JOIN t_user_role TUR ON TR.id = TUR.role_id\n" +
            "WHERE TUR.user_id = #{userId};")
    List<Role> getAllRoles(@Param("id") Integer userId);

    @Select("select * from t_role")
    List<Role> findAllRole ();

    @Insert("insert into t_role values(#{name},#{keyword},#{description})")
    void addRole(Role role);

    @Delete("delete from t_role where id=#{id}")
    void deleteRole(Integer id);

    @Update("update t_role set name=#{name},keyword=#{keyword},description=#{description} where id=#{id}")
    void updateRole(Role role);


}

